package com.yanqu.road.logic.sort;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

/**
 * @Author wpj
 * @Date 2020/9/3
 */
public class SkinCrossRankSort extends CrossRankSort {
    @Override
    public int compare(CrossUserRank o1, CrossUserRank o2) {
        int result = o2.getValue().compareTo(o1.getValue());
        if (result != 0) {
            return result;
        }

        JSONObject o2JsonObject = JSONObject.parseObject(o2.getParam());
        JSONObject o1JsonObject = JSONObject.parseObject(o1.getParam());
        // 值
        result = new BigInteger(StringUtils.isNullOrEmpty(o2JsonObject.getString("value")) ? "0" : o2JsonObject.getString("value")).compareTo(new BigInteger(StringUtils.isNullOrEmpty(o1JsonObject.getString("value")) ? "0" : o1JsonObject.getString("value")));
        if (result != 0) {
            return result;
        }


        long time = o1.getLastUpdateTime() - o2.getLastUpdateTime();
        result = time > 0 ? 1 : (time == 0 ? 0 : -1);
        return result;
    }
}
